<link href="<?php echo ThemePath(); ?>/css/inbox/style.css" rel="stylesheet" type="text/css" />
<div class="featureBox">
    <div class="container">
        <div class="row">
            <div class="span12">            	
                <ul class="breadcrumb">
                    <li class="previous"><a href="<?php echo SITE_URL; ?>">Home /</a></li>
                    <li><a href="javascript:void(0)">Inbox</a></li>
                </ul>                    
            </div>

            <?php if (count($inboxAll) > 0) { ?>	
                <div id="AjaxLoader_id" style="display:none;" align="center">&nbsp;<img src="<?php echo ThemePath(); ?>/images/fancybox_loading@2x.gif" align="absmiddle"></div>

                <div class="span6" style=" width: 0px !important;"> 
                    <div id="w">
                        <div id="navmenu">
                            <ul>
                                <?php
                                foreach ($inboxAll as $inbox) {
                                    $userDetails = Profiles::model()->findByAttributes(array('user_id' => $inbox->from_users_id));
                                    $imagePath = $inbox->from_users_id;
                                    if ($userDetails->photo <> "") {
                                        $imgsrc = baseUrl() . '../../' . getUploadDir() . $imagePath . '/profile/minithumb/' . $userDetails->photo;
                                    } else {
                                        $imgsrc = baseUrl() . '../../upload/default-mini.png';
                                    }
                                    ?>

                                    <li>
                                        <a href="javascript:void(0);" class="navlink" onclick="return MessageByuserId(<?php echo $inbox->from_users_id; ?>,<?php echo $inbox->to_user_id; ?>,<?php echo $inbox->classes_id; ?>);">
                                            <img src="<?php echo $imgsrc; ?>" title="<?php echo $userDetails->first_name; ?>" alt="<?php echo $userDetails->first_name; ?>" />
                                            <?php echo $inbox->classes->class_titile; ?><br />
                                            <?php echo $userDetails->first_name; ?>
                                        </a>
                                    </li>

                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                </div>

                <div style="float:right;background-color:#FFFFFF; width:720px; padding:3px; " id="detailInbox"></div>
                <script language="javascript">
                    $(document).ready(function() {
                        MessageByuserId(<?php echo $inboxAll[0]->from_users_id; ?>,<?php echo $inboxAll[0]->to_user_id; ?>,<?php echo $inboxAll[0]->classes_id; ?>);
                    });
                </script>
            <?php } else { ?>
                No any mail.
            <?php } ?>




        </div>
    </div>


    <script language="javascript">

        function MessageByuserId(fromuid,touid,classid) {
            jQuery.ajax({
                'type': 'POST',
                'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/GetMessage"); ?>",
                data: 'classid=' + classid+'&fromuid=' + fromuid+'&touid=' + touid ,
                'success': function(data) {
                    $('#detailInbox').html(data);
	   
                },
                'cache': false});

        }
        function showMsgBlock(checkval) {
            if(checkval==1){$("#replybtn").hide();}else{$("#replybtn").show();}
            $("#send_a_msg_box").toggle('slow').show();
        }


        function replyAMailToUser(classid, userid, getMessagesUID) {
            var subject = $("#subject_id").val();
            var msgval = $("#message_text_id").val();

            if (msgval == '') {
                $("#errorMessage_msg_id").text('Message  can not blank.')
                return false;
            }
            if(subject != '' && msgval != '') {
                jQuery.ajax({
                    'type': 'POST',
                    'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/sendMailTouser"); ?>",
                    'data': "selectedUser=" + userid + "&subject=" + subject + "&msgval=" + msgval + "&classId=" + classid,
                    'beforeSend': function(jqXHR, settings) {
                        $("#AjaxLoader_id").show();
                    },
                    'success': function(data) {
                        if($.trim(data)=='success') {
                            $("#AjaxLoader_id").hide();
                            MessageByuserId(userid,getMessagesUID,classid);
                        }
                    },
                    'cache': false
                });
            }

        }


    </script>